// lib/pages/innovation_project_page.dart
import 'package:flutter/material.dart';
import 'package:portal_website/pages/common_header.dart';
import 'package:portal_website/tool/color_util.dart';

class DoubleProjectPage extends StatefulWidget {
  const DoubleProjectPage({super.key});

  @override
  State<DoubleProjectPage> createState() => _InnovationProjectPageState();
}

class _InnovationProjectPageState extends State<DoubleProjectPage>
    with SingleTickerProviderStateMixin {
  late AnimationController _animationController;
  late List<Animation<double>> _animations;

  final List<Map<String, dynamic>> _projects = [
    {
      'name': '智能制造示范工厂',
      'type': '已成功',
      'description':
          '通过引进先进的智能制造技术，实现了生产过程的自动化和智能化，生产效率提升300%，产品质量显著提高，成为行业标杆企业。',
      'stats': {'年产值': '2.5亿', '创造就业': '300+人'}
    },
    {
      'name': '生态农业综合体',
      'type': '已成功',
      'description': '整合农业种植、农产品加工、乡村旅游等产业链，形成了完整的生态农业发展模式，带动周边农户共同致富。',
      'stats': {'年产值': '1.8亿', '带动农户': '200+户'}
    },
    {
      'name': '智慧医疗服务平台',
      'type': '进行中',
      'description': '利用大数据和人工智能技术，构建线上线下一体化的医疗服务体系，为居民提供便捷高效的健康管理服务。',
      'stats': {'覆盖人群': '50万+', '合作医院': '30+家'}
    },
    {
      'name': '新能源汽车充电桩网络',
      'type': '进行中',
      'description': '构建覆盖全区的新能源汽车充电网络，解决新能源汽车用户充电难问题，促进绿色出行。',
      'stats': {'已建桩数': '200+', '覆盖区域': '80%'}
    },
    {
      'name': '数字文化创意产业园',
      'type': '规划中',
      'description': '打造集创意设计、内容制作、展示交易于一体的数字文化产业集聚区，吸引文创企业和人才落户。',
      'stats': {'规划面积': '500亩', '预计投资': '10亿'}
    },
    {
      'name': '跨境电商孵化中心',
      'type': '规划中',
      'description': '为中小企业提供跨境电商全流程服务，包括平台搭建、海外推广、物流通关等，助力企业开拓国际市场。',
      'stats': {'计划入驻': '100+企业', '年交易额': '5亿+'}
    },
  ];

  final List<Map<String, dynamic>> _features = [
    {'icon': '🚀', 'title': '产业引领', 'description': '聚焦战略性新兴产业，培育具有核心竞争力的龙头项目'},
    {'icon': '💡', 'title': '创新驱动', 'description': '鼓励技术创新和模式创新，提升项目科技含量和附加值'},
    {'icon': '🤝', 'title': '合作共赢', 'description': '搭建产学研合作平台，促进创新资源整合与共享'},
    {'icon': '🌱', 'title': '持续孵化', 'description': '提供全生命周期服务，助力项目从创意到产业化的全过程'},
  ];

  @override
  void initState() {
    super.initState();
    _animationController = AnimationController(
      vsync: this,
      duration: const Duration(milliseconds: 1000),
    );

    _animations = List.generate(4, (index) {
      return Tween<double>(begin: 0, end: 1).animate(
        CurvedAnimation(
          parent: _animationController,
          curve: Interval(0.1 * index, 1.0, curve: Curves.easeOut),
        ),
      );
    });

    Future.delayed(const Duration(milliseconds: 100), () {
      _animationController.forward();
    });
  }

  @override
  void dispose() {
    _animationController.dispose();
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return AnimatedBuilder(
      animation: _animationController,
      builder: (context, child) {
        return Opacity(
          opacity: _animations[0].value,
          child: Transform.translate(
            offset: Offset(0, 30 * (1 - _animations[0].value)),
            child: child,
          ),
        );
      },
      child: Container(
        constraints: const BoxConstraints(maxWidth: 1200),
        padding: const EdgeInsets.all(20),
        child: Column(
          children: [
            const PageHeader(
              title: '双创项目',
              subtitle: '优质创新创业项目展示与对接',
              description:
                  '汇聚各类优秀创新创业项目，涵盖智能制造、生态农业、数字经济等多个领域，为项目方和投资方搭建合作桥梁，推动项目落地和产业化发展。',
            ),

            // 项目展示区域
            AnimatedBuilder(
              animation: _animationController,
              builder: (context, child) {
                return Opacity(
                  opacity: _animations[1].value,
                  child: Transform.translate(
                    offset: Offset(0, 30 * (1 - _animations[1].value)),
                    child: child,
                  ),
                );
              },
              child: ContentDoubleSection(
                title: '重点项目展示',
                subtitle: '精选优质项目，助力产业升级',
                content: GridView.count(
                  shrinkWrap: true,
                  physics: const NeverScrollableScrollPhysics(),
                  crossAxisCount:
                      MediaQuery.of(context).size.width > 768 ? 3 : 1,
                  crossAxisSpacing: 30,
                  mainAxisSpacing: 30,
                  childAspectRatio: 1.0,
                  children: _projects
                      .map((project) => _buildProjectCard(project))
                      .toList(),
                ),
              ),
            ),

            // 项目申报指南
            AnimatedBuilder(
              animation: _animationController,
              builder: (context, child) {
                return Opacity(
                  opacity: _animations[2].value,
                  child: Transform.translate(
                    offset: Offset(0, 30 * (1 - _animations[2].value)),
                    child: child,
                  ),
                );
              },
              child: ContentDoubleSection(
                title: '项目申报指南',
                subtitle: '如何申请成为重点扶持项目',
                content: Column(
                  crossAxisAlignment: CrossAxisAlignment.start,
                  children: [
                    const Text(
                      '为鼓励和支持创新创业项目发展，我区设立了重点项目扶持计划，符合以下条件的项目可申请扶持：',
                      style: TextStyle(
                        color: Color(0xFF555555),
                        height: 1.8,
                      ),
                    ),
                    SizedBox(height: 20),
                    const Text(
                      '一、申报条件',
                      style: TextStyle(
                        fontSize: 18,
                        color: Color(0xFF1e3c72),
                        fontWeight: FontWeight.bold,
                      ),
                    ),
                    SizedBox(height: 15),
                    _buildBulletPoint('1. 项目需符合国家产业政策和我区产业发展规划；'),
                    _buildBulletPoint('2. 具有较强的创新性和市场前景；'),
                    _buildBulletPoint('3. 拥有核心技术或独特商业模式；'),
                    _buildBulletPoint('4. 团队结构合理，具备实施项目的能力；'),
                    _buildBulletPoint('5. 无知识产权纠纷和法律风险。'),
                    const SizedBox(height: 20),
                    const Text(
                      '二、申报材料',
                      style: TextStyle(
                        fontSize: 18,
                        color: Color(0xFF1e3c72),
                        fontWeight: FontWeight.bold,
                      ),
                    ),
                    SizedBox(height: 15),
                    _buildBulletPoint('1. 项目申报书（含项目概况、市场分析、实施方案等）；'),
                    _buildBulletPoint('2. 营业执照或相关资质证明；'),
                    _buildBulletPoint('3. 知识产权证明材料；'),
                    _buildBulletPoint('4. 财务报表或资金证明；'),
                    _buildBulletPoint('5. 团队核心成员简历。'),
                    const SizedBox(height: 20),
                    const Text(
                      '三、申报流程',
                      style: TextStyle(
                        fontSize: 18,
                        color: Color(0xFF1e3c72),
                        fontWeight: FontWeight.bold,
                      ),
                    ),
                    SizedBox(height: 15),
                    _buildBulletPoint('1. 网上提交申报材料；'),
                    _buildBulletPoint('2. 材料初审和现场考察；'),
                    _buildBulletPoint('3. 专家评审和项目答辩；'),
                    _buildBulletPoint('4. 公示和立项；'),
                    _buildBulletPoint('5. 签订协议和资金拨付。'),
                    const SizedBox(height: 20),
                    Center(
                      child: ElevatedButton(
                        onPressed: () {},
                        style: ElevatedButton.styleFrom(
                          backgroundColor: const Color(0xFF4facfe),
                          padding: const EdgeInsets.symmetric(
                              horizontal: 30, vertical: 12),
                          shape: RoundedRectangleBorder(
                            borderRadius: BorderRadius.circular(30),
                          ),
                          elevation: 0,
                        ),
                        child: const Text(
                          '下载申报模板',
                          style: TextStyle(
                            color: Colors.white,
                            fontWeight: FontWeight.bold,
                          ),
                        ),
                      ),
                    ),
                  ],
                ),
              ),
            ),

            // 项目服务特色
            AnimatedBuilder(
              animation: _animationController,
              builder: (context, child) {
                return Opacity(
                  opacity: _animations[3].value,
                  child: Transform.translate(
                    offset: Offset(0, 30 * (1 - _animations[3].value)),
                    child: child,
                  ),
                );
              },
              child: ContentDoubleSection(
                title: '项目服务特色',
                subtitle: '全方位支持项目成长',
                content: GridView.count(
                  shrinkWrap: true,
                  physics: const NeverScrollableScrollPhysics(),
                  crossAxisCount:
                      MediaQuery.of(context).size.width > 768 ? 4 : 1,
                  crossAxisSpacing: 25,
                  mainAxisSpacing: 25,
                  childAspectRatio: 1.0,
                  children: _features
                      .map((feature) => FeatureItem(
                            icon: feature['icon'],
                            title: feature['title'],
                            description: feature['description'],
                          ))
                      .toList(),
                ),
              ),
            ),

            // 联系方式
            AnimatedBuilder(
              animation: _animationController,
              builder: (context, child) {
                return Opacity(
                  opacity: _animations[3].value,
                  child: Transform.translate(
                    offset: Offset(0, 30 * (1 - _animations[3].value)),
                    child: child,
                  ),
                );
              },
              child: ContentDoubleSection(
                title: '联系方式',
                subtitle: '如有疑问，请联系我们',
                content: Column(
                  children: [
                    Container(
                      padding: EdgeInsets.all(40),
                      decoration: BoxDecoration(
                        color: ColorsUtil.colorFF5EA6FF,
                        borderRadius: BorderRadius.circular(10),
                      ),
                      child: Column(
                        children: [
                          Text(
                            "面向社会征集项目创意和高效的项目方案",
                            style: TextStyle(color: Colors.white, fontSize: 24),
                          ),
                          SizedBox(
                            height: 10,
                          ),
                          Text(
                              style:
                                  TextStyle(color: Colors.white, fontSize: 14),
                              "我们诚挚邀请社会各界人士、企业单位、科研机构积极参与项目创意征集活动。 您的优秀创意和高效方案将为创业者提供宝贵的参考，为区域经济发展注入新的活力。 我们将为优秀项目提供专业的评估、指导和资金支持，共同推动创新创业事业的发展。"),
                        ],
                      ),
                    ),
                    SizedBox(
                      height: 20,
                    ),
                    Row(
                      mainAxisAlignment: MainAxisAlignment.spaceBetween,
                      children: [
                        Container(
                          child: const Column(
                            crossAxisAlignment: CrossAxisAlignment.start,
                            mainAxisAlignment: MainAxisAlignment.spaceBetween,
                            children: [
                              Text(
                                '项目合作与咨询：',
                                style: TextStyle(
                                  fontSize: 16,
                                  fontWeight: FontWeight.bold,
                                ),
                              ),
                              SizedBox(height: 15),
                              Text(
                                '• 联系人：王老师',
                                style: TextStyle(
                                  color: Color(0xFF666666),
                                  height: 2,
                                ),
                              ),
                              Text(
                                '• 联系电话：0371-66666666',
                                style: TextStyle(
                                  color: Color(0xFF666666),
                                  height: 2,
                                ),
                              ),
                              Text(
                                '• 邮箱：project@demo.com',
                                style: TextStyle(
                                  color: Color(0xFF666666),
                                  height: 2,
                                ),
                              ),
                              Text(
                                '• 地址：城乡一体化示范区管委会',
                                style: TextStyle(
                                  color: Color(0xFF666666),
                                  height: 2,
                                ),
                              ),
                            ],
                          ),
                          padding: EdgeInsets.all(20),
                          decoration: BoxDecoration(
                              borderRadius: BorderRadius.circular(10),
                              border: Border.all(
                                  width: 1, color: ColorsUtil.colorFAFAFA)),
                        ),
                        Container(
                          child: const Column(
                            crossAxisAlignment: CrossAxisAlignment.start,
                            mainAxisAlignment: MainAxisAlignment.spaceBetween,
                            children: [
                              Text(
                                '项目合作与咨询：',
                                style: TextStyle(
                                  fontSize: 16,
                                  fontWeight: FontWeight.bold,
                                ),
                              ),
                              SizedBox(height: 15),
                              Text(
                                '• 联系人：王老师',
                                style: TextStyle(
                                  color: Color(0xFF666666),
                                  height: 2,
                                ),
                              ),
                              Text(
                                '• 联系电话：0371-66666666',
                                style: TextStyle(
                                  color: Color(0xFF666666),
                                  height: 2,
                                ),
                              ),
                              Text(
                                '• 邮箱：project@demo.com',
                                style: TextStyle(
                                  color: Color(0xFF666666),
                                  height: 2,
                                ),
                              ),
                              Text(
                                '• 地址：城乡一体化示范区管委会',
                                style: TextStyle(
                                  color: Color(0xFF666666),
                                  height: 2,
                                ),
                              ),
                            ],
                          ),
                          padding: EdgeInsets.all(20),
                          decoration: BoxDecoration(
                              borderRadius: BorderRadius.circular(10),
                              border: Border.all(
                                  width: 1, color: ColorsUtil.colorFAFAFA)),
                        ),
                        Container(
                          child: const Column(
                            crossAxisAlignment: CrossAxisAlignment.start,
                            mainAxisAlignment: MainAxisAlignment.spaceBetween,
                            children: [
                              Text(
                                '项目合作与咨询：',
                                style: TextStyle(
                                  fontSize: 16,
                                  fontWeight: FontWeight.bold,
                                ),
                              ),
                              SizedBox(height: 15),
                              Text(
                                '• 联系人：王老师',
                                style: TextStyle(
                                  color: Color(0xFF666666),
                                  height: 2,
                                ),
                              ),
                              Text(
                                '• 联系电话：0371-66666666',
                                style: TextStyle(
                                  color: Color(0xFF666666),
                                  height: 2,
                                ),
                              ),
                              Text(
                                '• 邮箱：project@demo.com',
                                style: TextStyle(
                                  color: Color(0xFF666666),
                                  height: 2,
                                ),
                              ),
                              Text(
                                '• 地址：城乡一体化示范区管委会',
                                style: TextStyle(
                                  color: Color(0xFF666666),
                                  height: 2,
                                ),
                              ),
                            ],
                          ),
                          padding: EdgeInsets.all(20),
                          decoration: BoxDecoration(
                              borderRadius: BorderRadius.circular(10),
                              border: Border.all(
                                  width: 1, color: ColorsUtil.colorFAFAFA)),
                        ),
                      ],
                    ),
                  ],
                ),
              ),
            ),
          ],
        ),
      ),
    );
  }

  Widget _buildProjectCard(Map<String, dynamic> project) {
    return MouseRegion(
      child: AnimatedContainer(
        duration: const Duration(milliseconds: 300),
        decoration: BoxDecoration(
          color: Colors.white,
          border: Border.all(color: const Color(0xFFe1e8ed)),
          borderRadius: BorderRadius.circular(12),
          boxShadow: const [
            BoxShadow(
              color: Colors.black12,
              blurRadius: 15,
              offset: Offset(0, 3),
            )
          ],
        ),
        child: Column(
          crossAxisAlignment: CrossAxisAlignment.start,
          children: [
            Container(
              height: 120,
              decoration: const BoxDecoration(
                gradient: LinearGradient(
                  colors: [Color(0xFF4facfe), Color(0xFF00f2fe)],
                  begin: Alignment.topLeft,
                  end: Alignment.bottomRight,
                ),
                borderRadius: BorderRadius.vertical(
                  top: Radius.circular(12),
                ),
              ),
              child: const Center(
                child: Text(
                  '🎯',
                  style: TextStyle(fontSize: 48, color: Colors.white),
                ),
              ),
            ),
            Padding(
              padding: const EdgeInsets.all(25),
              child: Column(
                crossAxisAlignment: CrossAxisAlignment.start,
                children: [
                  Text(
                    project['name'],
                    style: const TextStyle(
                      fontSize: 20,
                      color: Color(0xFF1e3c72),
                      fontWeight: FontWeight.bold,
                    ),
                  ),
                  SizedBox(height: 12),
                  Container(
                    margin: const EdgeInsets.only(bottom: 15),
                    padding:
                        const EdgeInsets.symmetric(horizontal: 12, vertical: 4),
                    decoration: const BoxDecoration(
                      gradient: LinearGradient(
                        colors: [Color(0xFF4facfe), Color(0xFF00f2fe)],
                      ),
                      borderRadius: BorderRadius.all(Radius.circular(20)),
                    ),
                    child: Text(
                      project['type'],
                      style: const TextStyle(
                        fontSize: 12,
                        color: Colors.white,
                        fontWeight: FontWeight.w500,
                      ),
                    ),
                  ),
                  Container(
                    child: Text(
                      project['description'],
                      maxLines: 3,
                      style: const TextStyle(
                        color: Color(0xFF666666),
                        height: 1.4,
                      ),
                    ),
                  ),
                  Row(
                    mainAxisAlignment: MainAxisAlignment.spaceBetween,
                    children: [
                      Text(
                        project['stats'].entries.first.key +
                            '：' +
                            project['stats'].entries.first.value,
                        style: const TextStyle(
                          fontSize: 13,
                          color: Color(0xFF888888),
                        ),
                      ),
                      Text(
                        project['stats'].entries.last.key +
                            '：' +
                            project['stats'].entries.last.value,
                        style: const TextStyle(
                          fontSize: 13,
                          color: Color(0xFF888888),
                        ),
                      ),
                    ],
                  ),
                ],
              ),
            ),
          ],
        ),
      ),
    );
  }

  Widget _buildBulletPoint(String text) {
    return Padding(
      padding: const EdgeInsets.only(bottom: 10),
      child: Row(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          const Text(
            '• ',
            style: TextStyle(color: Color(0xFF666666)),
          ),
          Expanded(
            child: Text(
              text,
              style: const TextStyle(
                color: Color(0xFF666666),
                height: 1.7,
              ),
            ),
          ),
        ],
      ),
    );
  }
}
